/**
 * 机勘院智能业务系统主JavaScript文件
 */

$(document).ready(function() {
    // 初始化页面
    initPage();
    
    // 初始化主题模式
    initThemeMode();
    
    // 绑定导航事件
    bindNavigationEvents();
    
    // 绑定移动端侧边栏切换
    bindSidebarToggle();
    
    // 绑定全局搜索
    bindGlobalSearch();
});

/**
 * 初始化页面
 */
function initPage() {
    // 默认激活首页导航
    $('#home-link').addClass('active');
    
    // 检查用户会话状态
    checkUserSession();
    
    // 适配移动设备
    handleResponsiveLayout();
    
    // 初始化提示工具
    initTooltips();
    
    // 直接加载首页内容，跳过欢迎页面
    loadHomePage();
}

/**
 * 初始化主题模式
 */
function initThemeMode() {
    // 检查本地存储中的主题模式设置
    const isDarkMode = localStorage.getItem('darkMode') === 'true';
    
    // 应用主题模式
    if (isDarkMode) {
        $('body').addClass('dark-mode');
        $('#themeToggle i').removeClass('fa-moon').addClass('fa-sun');
    }
    
    // 绑定主题切换按钮事件
    $('#themeToggle').on('click', function() {
        $('body').toggleClass('dark-mode');
        const isDarkModeNow = $('body').hasClass('dark-mode');
        
        // 更新图标
        if (isDarkModeNow) {
            $('#themeToggle i').removeClass('fa-moon').addClass('fa-sun');
        } else {
            $('#themeToggle i').removeClass('fa-sun').addClass('fa-moon');
        }
        
        // 保存设置到本地存储
        localStorage.setItem('darkMode', isDarkModeNow);
    });
}

/**
 * 检查用户会话状态
 */
function checkUserSession() {
    // 这里可以添加验证用户是否登录的代码
    // 如果未登录，可以重定向到登录页面
    
    // 模拟用户已登录
    console.log('用户会话检查成功');
}

/**
 * 适配移动设备
 */
function handleResponsiveLayout() {
    // 检查屏幕尺寸，调整界面元素
    const isMobile = window.innerWidth < 992;
    
    if (isMobile) {
        $('#sidebar').removeClass('show');
    } else {
        $('#sidebar').addClass('show');
    }
    
    // 监听窗口大小变化事件
    $(window).resize(function() {
        const isMobileNow = window.innerWidth < 992;
        
        if (isMobileNow) {
            $('#sidebar').removeClass('show');
        } else {
            $('#sidebar').addClass('show');
            $('#sidebarOverlay').removeClass('show');
        }
    });
}

/**
 * 初始化提示工具
 */
function initTooltips() {
    // 初始化Bootstrap工具提示
    const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl);
    });
}

/**
 * 绑定导航事件
 */
function bindNavigationEvents() {
    // 主导航项点击事件
    $('.deepseek-nav-item').on('click', function(e) {
        const hasSubmenu = $(this).attr('data-bs-toggle') === 'collapse';
        const isExternalLink = $(this).attr('href') && $(this).attr('href').indexOf('pages/') === 0;
        
        // 如果是带子菜单的导航项或外部链接，则不阻止默认行为
        if (hasSubmenu || isExternalLink) return;
        
        e.preventDefault();
        activateNavItem($(this));
        
        // 根据ID加载对应内容
        const id = $(this).attr('id');
        switch (id) {
            case 'home-link':
                loadHomePage();
                break;
            case 'chat-link':
                loadChatPage();
                break;
            case 'data-link':
                loadDataAnalyticsPage();
                break;
            case 'help-link':
                loadHelpPage();
                break;
            default:
                break;
        }
    });
    
    // 子菜单项点击事件
    $(document).on('click', '.deepseek-nav-dropdown-item', function(e) {
        e.preventDefault();
        
        console.log('子菜单点击:', $(this).data('action'));
        
        // 移除所有子菜单项的active类
        $('.deepseek-nav-dropdown-item').removeClass('active');
        
        // 将active类添加到当前子菜单项
        $(this).addClass('active');
        
        // 激活父级导航项
        const parentMenuId = $(this).parent().attr('id');
        $(`[data-bs-target="#${parentMenuId}"]`).addClass('active');
        
        // 加载对应内容
        const action = $(this).data('action');
        handleSubMenuAction(action);
        
        // 如果是移动设备，收起侧边栏
        if (window.innerWidth < 992) {
            $('#sidebar').removeClass('show');
            $('#sidebarOverlay').removeClass('show');
        }
    });
}

/**
 * 处理子菜单操作
 * @param {string} action - 操作标识
 */
function handleSubMenuAction(action) {
    console.log(`处理子菜单操作: ${action}`);
    
    // 文件相关操作
    if (action === 'allFiles' || action === 'recentFiles' || action === 'sharedFiles' || action === 'uploadFile') {
        loadFilePage(action);
        return;
    }
    
    // 知识库相关操作
    if (action === 'browseKnowledge' || action === 'searchKnowledge' || action === 'createKnowledge' || action === 'manageKnowledge') {
        loadKnowledgePage(action);
        return;
    }
    
    // 系统管理相关操作
    if (action === 'systemConfig' || action === 'userManagement' || action === 'rolesPermissions' || 
        action === 'systemLogs' || action === 'dataBackup' || action === 'aiConfig') {
        console.log('加载系统管理操作:', action);
        loadSystemPage(action);
        return;
    }
    
    console.log('未知操作:', action);
}

/**
 * 绑定侧边栏切换
 */
function bindSidebarToggle() {
    // 侧边栏切换按钮点击事件
    $('#sidebarToggle').on('click', function() {
        $('#sidebar').toggleClass('show');
        $('#sidebarOverlay').toggleClass('show');
    });
    
    // 侧边栏遮罩点击事件
    $('#sidebarOverlay').on('click', function() {
        $('#sidebar').removeClass('show');
        $(this).removeClass('show');
    });
}

/**
 * 绑定全局搜索
 */
function bindGlobalSearch() {
    $('#globalSearch').on('keyup', function(e) {
        if (e.key === 'Enter') {
            const query = $(this).val().trim();
            if (query) {
                performGlobalSearch(query);
            }
        }
    });
}

/**
 * 执行全局搜索
 * @param {string} query - 搜索查询
 */
function performGlobalSearch(query) {
    console.log(`执行全局搜索: ${query}`);
    // 在这里添加全局搜索逻辑
    showNotification('搜索功能', `正在搜索: "${query}"`, 'info');
    
    // 示例：加载搜索结果页面
    $('#main-content').html(`
        <div class="deepseek-page-header">
            <h4>搜索结果: "${query}"</h4>
        </div>
        <div class="deepseek-card">
            <div class="deepseek-card-body">
                <div class="search-results">
                    <p class="text-muted">正在加载搜索结果...</p>
                    <div class="spinner-border text-primary" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                </div>
            </div>
        </div>
    `);
    
    // 模拟延迟加载搜索结果
    setTimeout(function() {
        $('.search-results').html(`
            <div class="mb-4">
                <h5>文件 (3)</h5>
                <div class="list-group">
                    <a href="#" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">项目报告.docx</h6>
                            <small>3天前</small>
                        </div>
                        <p class="mb-1 text-truncate">...包含 "${query}" 的内容...</p>
                    </a>
                    <a href="#" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">数据分析.xlsx</h6>
                            <small>上周</small>
                        </div>
                        <p class="mb-1 text-truncate">...包含 "${query}" 的表格...</p>
                    </a>
                    <a href="#" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">会议记录.pdf</h6>
                            <small>2周前</small>
                        </div>
                        <p class="mb-1 text-truncate">...关于 "${query}" 的讨论...</p>
                    </a>
                </div>
            </div>
            
            <div class="mb-4">
                <h5>知识库 (2)</h5>
                <div class="list-group">
                    <a href="#" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">技术规范</h6>
                            <small>更新于昨天</small>
                        </div>
                        <p class="mb-1 text-truncate">...与 "${query}" 相关的技术说明...</p>
                    </a>
                    <a href="#" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">操作指南</h6>
                            <small>更新于上月</small>
                        </div>
                        <p class="mb-1 text-truncate">...关于 "${query}" 的使用方法...</p>
                    </a>
                </div>
            </div>
        `);
    }, 1500);
}

/**
 * 显示通知
 * @param {string} title - 通知标题
 * @param {string} message - 通知内容
 * @param {string} type - 通知类型 (success, error, info, warning)
 */
function showNotification(title, message, type = 'info') {
    // 创建通知元素
    const notificationId = 'notification-' + Date.now();
    const notification = $(`
        <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" id="${notificationId}">
            <div class="toast-header">
                <div class="bg-${type} rounded me-2" style="width: 20px; height: 20px;"></div>
                <strong class="me-auto">${title}</strong>
                <small>刚刚</small>
                <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
            </div>
            <div class="toast-body">
                ${message}
            </div>
        </div>
    `);
    
    // 检查通知容器是否存在，不存在则创建
    let toastContainer = $('.toast-container');
    if (toastContainer.length === 0) {
        toastContainer = $('<div class="toast-container position-fixed top-0 end-0 p-3"></div>');
        $('body').append(toastContainer);
    }
    
    // 添加通知到容器
    toastContainer.append(notification);
    
    // 显示通知
    const toast = new bootstrap.Toast(document.getElementById(notificationId), {
        autohide: true,
        delay: 5000
    });
    toast.show();
}

/**
 * 激活导航项目
 * @param {jQuery} navItem - 导航项目
 */
function activateNavItem(navItem) {
    // 移除所有导航项的active类
    $('.deepseek-nav-item').removeClass('active');
    
    // 将active类添加到当前导航项
    navItem.addClass('active');
    
    // 如果是移动设备，收起侧边栏
    if (window.innerWidth < 992) {
        $('#sidebar').removeClass('show');
        $('#sidebarOverlay').removeClass('show');
    }
}

/**
 * 加载首页内容
 */
function loadHomePage() {
    $('#main-content').html(`
        <div class="deepseek-page-header mb-4">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h4 class="mb-1">欢迎使用机勘院智能业务系统</h4>
                    <p class="text-muted mb-0">智能、高效的工作平台</p>
                </div>
                <div class="d-none d-md-block">
                    <div class="badge bg-primary-subtle text-primary p-2 rounded-pill">
                        <i class="fas fa-check-circle me-1"></i> 系统状态: 正常运行中
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 顶部摘要卡片 - 使用渐变背景 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="deepseek-card home-highlight-card">
                    <div class="row g-0">
                        <div class="col-md-8 p-4">
                            <h3 class="text-white mb-3">智能化工作，提升效率</h3>
                            <p class="text-white-50 mb-4">使用机勘院智能业务系统，让AI助力您的日常工作，智能处理文档，快速获取知识，有效进行沟通。</p>
                            <div class="d-flex gap-2">
                                <button class="btn btn-light" onclick="$('#chat-link').trigger('click')">
                                    <i class="fas fa-robot me-2"></i>开始智能对话
                                </button>
                                <button class="btn btn-outline-light" onclick="$('#file-link').trigger('click')">
                                    <i class="fas fa-upload me-2"></i>上传文件
                                </button>
                            </div>
                        </div>
                        <div class="col-md-4 d-none d-md-flex align-items-center justify-content-center p-4">
                            <div class="home-highlight-image">
                                <i class="fas fa-brain fa-6x text-white-50"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 统计卡片 - 现代风格 -->
        <div class="row g-3 mb-4">
            <div class="col-sm-6 col-xl-3">
                <div class="deepseek-stat-card hover-lift">
                    <div class="icon bg-primary-subtle text-primary"><i class="fas fa-file"></i></div>
                    <div class="label">文件总数</div>
                    <div class="value" data-count="856">856</div>
                    <div class="change positive">
                        <i class="fas fa-arrow-up"></i>
                        <span>12% 本周</span>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-xl-3">
                <div class="deepseek-stat-card hover-lift">
                    <div class="icon bg-success-subtle text-success"><i class="fas fa-comments"></i></div>
                    <div class="label">对话次数</div>
                    <div class="value" data-count="1259">1,259</div>
                    <div class="change positive">
                        <i class="fas fa-arrow-up"></i>
                        <span>8% 本周</span>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-xl-3">
                <div class="deepseek-stat-card hover-lift">
                    <div class="icon bg-info-subtle text-info"><i class="fas fa-book"></i></div>
                    <div class="label">知识条目</div>
                    <div class="value" data-count="421">421</div>
                    <div class="change positive">
                        <i class="fas fa-arrow-up"></i>
                        <span>5% 本周</span>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-xl-3">
                <div class="deepseek-stat-card hover-lift">
                    <div class="icon bg-warning-subtle text-warning"><i class="fas fa-users"></i></div>
                    <div class="label">活跃用户</div>
                    <div class="value" data-count="38">38</div>
                    <div class="change negative">
                        <i class="fas fa-arrow-down"></i>
                        <span>3% 本周</span>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row g-3 mb-4">
            <!-- 快捷功能卡片 - 重新设计 -->
            <div class="col-lg-4 mb-4 mb-lg-0">
                <div class="deepseek-card h-100 hover-lift">
                    <div class="deepseek-card-header border-bottom-0">
                        <h5 class="deepseek-card-title mb-0">快捷操作</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="row g-3">
                            <div class="col-6">
                                <div class="feature-shortcut d-flex flex-column align-items-center text-center p-3 rounded hover-primary-light" onclick="$('#chat-link').trigger('click')">
                                    <div class="icon-wrapper bg-primary-subtle rounded-circle mb-2">
                                        <i class="fas fa-comments text-primary"></i>
                                    </div>
                                    <span>智能会话</span>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="feature-shortcut d-flex flex-column align-items-center text-center p-3 rounded hover-primary-light" onclick="$('#file-link').trigger('click')">
                                    <div class="icon-wrapper bg-success-subtle rounded-circle mb-2">
                                        <i class="fas fa-upload text-success"></i>
                                    </div>
                                    <span>上传文件</span>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="feature-shortcut d-flex flex-column align-items-center text-center p-3 rounded hover-primary-light" onclick="$('#knowledge-link').trigger('click')">
                                    <div class="icon-wrapper bg-info-subtle rounded-circle mb-2">
                                        <i class="fas fa-book text-info"></i>
                                    </div>
                                    <span>查询知识</span>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="feature-shortcut d-flex flex-column align-items-center text-center p-3 rounded hover-primary-light" onclick="$('#data-link').trigger('click')">
                                    <div class="icon-wrapper bg-warning-subtle rounded-circle mb-2">
                                        <i class="fas fa-chart-bar text-warning"></i>
                                    </div>
                                    <span>数据分析</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 最近活动 - 使用更丰富的视觉样式 -->
            <div class="col-lg-4 mb-4 mb-lg-0">
                <div class="deepseek-card h-100 hover-lift">
                    <div class="deepseek-card-header d-flex justify-content-between align-items-center border-bottom-0">
                        <h5 class="deepseek-card-title mb-0">最近活动</h5>
                        <a href="#" class="btn btn-sm btn-link p-0">查看全部</a>
                    </div>
                    <div class="deepseek-card-body p-0">
                        <div class="activity-timeline px-3">
                            <div class="activity-item">
                                <div class="activity-dot bg-primary"></div>
                                <div class="activity-content">
                                    <div class="d-flex justify-content-between">
                                        <h6 class="mb-0 text-truncate">上传了新文件</h6>
                                        <small class="text-muted ms-2">3分钟前</small>
                                    </div>
                                    <p class="mb-0 text-truncate">项目报告.docx</p>
                                    <small class="text-muted">由 张三 上传</small>
                                </div>
                            </div>
                            <div class="activity-item">
                                <div class="activity-dot bg-success"></div>
                                <div class="activity-content">
                                    <div class="d-flex justify-content-between">
                                        <h6 class="mb-0 text-truncate">更新了知识库</h6>
                                        <small class="text-muted ms-2">2小时前</small>
                                    </div>
                                    <p class="mb-0 text-truncate">产品技术规范</p>
                                    <small class="text-muted">由 李四 更新</small>
                                </div>
                            </div>
                            <div class="activity-item">
                                <div class="activity-dot bg-info"></div>
                                <div class="activity-content">
                                    <div class="d-flex justify-content-between">
                                        <h6 class="mb-0 text-truncate">开始智能对话</h6>
                                        <small class="text-muted ms-2">昨天</small>
                                    </div>
                                    <p class="mb-0 text-truncate">关于数据分析的问题</p>
                                    <small class="text-muted">由 王五 发起</small>
                                </div>
                            </div>
                            <div class="activity-item">
                                <div class="activity-dot bg-warning"></div>
                                <div class="activity-content">
                                    <div class="d-flex justify-content-between">
                                        <h6 class="mb-0 text-truncate">分享了文件</h6>
                                        <small class="text-muted ms-2">前天</small>
                                    </div>
                                    <p class="mb-0 text-truncate">会议记录.pdf</p>
                                    <small class="text-muted">由 赵六 分享给团队</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 系统公告 - 更现代化的设计 -->
            <div class="col-lg-4">
                <div class="deepseek-card h-100 hover-lift">
                    <div class="deepseek-card-header d-flex justify-content-between align-items-center border-bottom-0">
                        <h5 class="deepseek-card-title mb-0">系统公告</h5>
                        <span class="badge bg-primary rounded-pill">2条新消息</span>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="announcement-item mb-3">
                            <div class="announcement-badge bg-primary-subtle text-primary">
                                <i class="fas fa-info-circle"></i>
                            </div>
                            <div class="announcement-content">
                                <h6>系统升级通知</h6>
                                <p class="mb-1">系统将于本周六凌晨2:00-4:00进行例行维护升级，届时系统将暂停服务。</p>
                                <div class="d-flex align-items-center">
                                    <small class="text-muted">发布于 2023-03-01</small>
                                    <a href="#" class="btn btn-sm btn-link ms-auto p-0">详情</a>
                                </div>
                            </div>
                        </div>
                        <div class="announcement-item">
                            <div class="announcement-badge bg-success-subtle text-success">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div class="announcement-content">
                                <h6>新功能上线</h6>
                                <p class="mb-1">数据分析模块已正式上线，欢迎体验使用！</p>
                                <div class="d-flex align-items-center">
                                    <small class="text-muted">发布于 2023-02-15</small>
                                    <a href="#" class="btn btn-sm btn-link ms-auto p-0">详情</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    `);
    
    // 初始化首页的交互效果
    initHomePageInteractions();
}

/**
 * 初始化首页的交互效果
 */
function initHomePageInteractions() {
    // 数字计数动画效果
    $('.deepseek-stat-card .value').each(function() {
        const $this = $(this);
        const countTo = parseInt($this.attr('data-count'));
        
        $({ countNum: 0 }).animate({
            countNum: countTo
        }, {
            duration: 1000,
            easing: 'swing',
            step: function() {
                $this.text(Math.floor(this.countNum).toLocaleString());
            },
            complete: function() {
                $this.text(countTo.toLocaleString());
            }
        });
    });
}

/**
 * 加载智能会话页面
 */
function loadChatPage() {
    $('#main-content').html(`
        <div class="chat-layout">
            <!-- 聊天主区域 -->
            <div class="chat-main">
                <!-- 聊天头部 -->
                <div class="chat-header">
                    <div class="d-flex align-items-center">
                        <div class="chat-avatar">
                            <i class="fas fa-robot"></i>
                        </div>
                        <div class="ms-3">
                            <h5 class="mb-0">机勘院智能助手</h5>
                            <div class="chat-status online">
                                <span class="status-dot"></span>
                                <span class="status-text">在线</span>
                            </div>
                        </div>
                    </div>
                    <div class="chat-actions">
                        <button class="btn btn-sm btn-outline-secondary" id="clearChatBtn">
                            <i class="fas fa-broom me-1"></i>清空对话
                        </button>
                        <button class="btn btn-sm btn-outline-primary ms-2" id="exportChatBtn">
                            <i class="fas fa-download me-1"></i>导出对话
                        </button>
                    </div>
                </div>
                
                <!-- 消息区域 -->
                <div class="chat-messages" id="chat-messages">
                    <div class="chat-date-divider">
                        <span>今天</span>
                    </div>
                    
                    <div class="message-wrapper">
                        <div class="message message-bot">
                            <div class="message-header">
                                <div class="message-avatar">
                                    <i class="fas fa-robot"></i>
                                </div>
                                <div class="message-info">
                                    <div class="message-sender">机勘院智能助手</div>
                                    <div class="message-time">12:00</div>
                                </div>
                            </div>
                            <div class="message-content">
                                <p>您好，我是机勘院智能业务系统助手，很高兴为您服务。请问有什么可以帮助您的？</p>
                                <p>您可以询问我关于道路勘察、地质勘测、工程设计等方面的问题。</p>
                            </div>
                            <div class="message-actions">
                                <button class="btn btn-sm btn-link btn-message-action" title="复制"><i class="fas fa-copy"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 输入区域 -->
                <div class="chat-input-container">
                    <div class="chat-input-toolbar">
                        <button class="btn btn-tool" title="上传文件"><i class="fas fa-paperclip"></i></button>
                        <button class="btn btn-tool" title="表情符号"><i class="fas fa-smile"></i></button>
                        <button class="btn btn-tool" title="语音输入"><i class="fas fa-microphone"></i></button>
                    </div>
                    <div class="chat-input-wrapper">
                        <textarea class="form-control" id="chat-input-text" rows="1" placeholder="请输入您的问题..."></textarea>
                        <button class="btn btn-primary btn-send" id="send-message-btn">
                            <i class="fas fa-paper-plane"></i>
                        </button>
                    </div>
                    <div class="chat-input-footer">
                        <small class="text-muted">按下Enter键发送，Shift+Enter键换行</small>
                        <div class="chat-suggestions" id="chat-suggestions">
                            <button class="suggestion-item">道路勘察流程</button>
                            <button class="suggestion-item">工程设计标准</button>
                            <button class="suggestion-item">地质勘测报告格式</button>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 右侧信息栏 -->
            <div class="chat-info-panel">
                <div class="info-panel-header">
                    <h6 class="mb-0">对话信息</h6>
                    <button class="btn btn-sm btn-link p-0" id="collapseInfoPanel">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
                
                <div class="info-panel-section">
                    <h6 class="section-title">对话统计</h6>
                    <div class="info-card">
                        <div class="info-item">
                            <div class="info-label">对话轮次</div>
                            <div class="info-value" id="chatTurns">1</div>
                        </div>
                        <div class="info-item">
                            <div class="info-label">用户消息</div>
                            <div class="info-value" id="userMessages">0</div>
                        </div>
                        <div class="info-item">
                            <div class="info-label">AI响应</div>
                            <div class="info-value" id="botMessages">1</div>
                        </div>
                    </div>
                </div>
                
                <div class="info-panel-section">
                    <h6 class="section-title">会话设置</h6>
                    <div class="setting-item">
                        <label class="form-label">响应模式</label>
                        <select class="form-select form-select-sm" id="responseMode">
                            <option value="balanced" selected>平衡</option>
                            <option value="creative">创造性</option>
                            <option value="precise">精确</option>
                        </select>
                    </div>
                    <div class="setting-item">
                        <label class="form-label d-flex justify-content-between">
                            <span>智能建议</span>
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" id="suggestionToggle" checked>
                            </div>
                        </label>
                    </div>
                    <div class="setting-item">
                        <label class="form-label d-flex justify-content-between">
                            <span>引用文档信息</span>
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" id="citationToggle" checked>
                            </div>
                        </label>
                    </div>
                </div>
                
                <div class="info-panel-section">
                    <h6 class="section-title">相关资源</h6>
                    <div class="resource-list">
                        <a href="#" class="resource-item">
                            <i class="fas fa-file-pdf text-danger me-2"></i>
                            <span class="resource-name">道路勘察手册.pdf</span>
                        </a>
                        <a href="#" class="resource-item">
                            <i class="fas fa-file-word text-primary me-2"></i>
                            <span class="resource-name">工程设计规范.docx</span>
                        </a>
                        <a href="#" class="resource-item">
                            <i class="fas fa-file-excel text-success me-2"></i>
                            <span class="resource-name">勘测数据分析.xlsx</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    `);
    
    // 初始化UI交互
    initChatUI();
    
    // 绑定发送消息事件
    $('#send-message-btn').on('click', sendChatMessage);
    
    // 键盘事件处理
    $('#chat-input-text').on('keydown', function(e) {
        // Enter键发送，Shift+Enter换行
        if (e.key === 'Enter' && !e.shiftKey) {
            e.preventDefault();
            sendChatMessage();
        }
        
        // 自动调整文本框高度
        autoResizeTextarea(this);
    });
    
    // 输入事件处理自动调整文本框高度
    $('#chat-input-text').on('input', function() {
        autoResizeTextarea(this);
    });
    
    // 绑定建议点击事件
    $('.suggestion-item').on('click', function() {
        $('#chat-input-text').val($(this).text());
        sendChatMessage();
    });
    
    // 绑定清空对话事件
    $('#clearChatBtn').on('click', function() {
        if (confirm('确定要清空当前对话吗？')) {
            resetChat();
        }
    });
    
    // 绑定导出对话事件
    $('#exportChatBtn').on('click', exportChatHistory);
    
    // 绑定折叠信息面板事件
    $('#collapseInfoPanel').on('click', function() {
        $('.chat-layout').toggleClass('info-panel-collapsed');
    });
}

/**
 * 初始化聊天UI
 */
function initChatUI() {
    // 设置消息区域滚动到底部
    scrollChatToBottom();
    
    // 设置文本框自动获取焦点
    $('#chat-input-text').focus();
    
    // 初始化输入区域大小
    autoResizeTextarea(document.getElementById('chat-input-text'));
    
    // 初始化提示工具
    $('[title]').tooltip();
}

/**
 * 文本框高度自适应
 * @param {HTMLElement} textarea - 文本框元素
 */
function autoResizeTextarea(textarea) {
    // 重置高度
    $(textarea).css('height', 'auto');
    
    // 计算新高度
    const newHeight = Math.min(textarea.scrollHeight, 120); // 最大高度120px
    
    // 设置新高度
    $(textarea).css('height', newHeight + 'px');
}

/**
 * 发送聊天消息
 */
function sendChatMessage() {
    const messageText = $('#chat-input-text').val().trim();
    
    // 检查消息是否为空
    if (messageText === '') {
        return;
    }
    
    // 获取当前时间
    const now = new Date();
    const timeStr = now.getHours().toString().padStart(2, '0') + ':' + 
                   now.getMinutes().toString().padStart(2, '0');
    
    // 添加用户消息到聊天界面
    $('#chat-messages').append(`
        <div class="message-wrapper user-message-wrapper">
            <div class="message message-user">
                <div class="message-header">
                    <div class="message-info">
                        <div class="message-sender">您</div>
                        <div class="message-time">${timeStr}</div>
                    </div>
                    <div class="message-avatar">
                        <i class="fas fa-user"></i>
                    </div>
                </div>
                <div class="message-content">
                    <p>${messageText}</p>
                </div>
                <div class="message-actions">
                    <button class="btn btn-sm btn-link btn-message-action" title="编辑"><i class="fas fa-edit"></i></button>
                    <button class="btn btn-sm btn-link btn-message-action" title="复制"><i class="fas fa-copy"></i></button>
                </div>
            </div>
        </div>
    `);
    
    // 清空输入框并重置高度
    $('#chat-input-text').val('').css('height', 'auto');
    
    // 更新聊天统计数据
    updateChatStats();
    
    // 滚动到底部
    scrollChatToBottom();
    
    // 显示AI正在输入
    $('#chat-messages').append(`
        <div class="message-wrapper" id="typing-indicator-wrapper">
            <div class="message message-bot typing">
                <div class="message-header">
                    <div class="message-avatar">
                        <i class="fas fa-robot"></i>
                    </div>
                    <div class="message-info">
                        <div class="message-sender">机勘院智能助手</div>
                        <div class="message-time">${timeStr}</div>
                    </div>
                </div>
                <div class="message-content">
                    <div class="typing-indicator">
                        <span></span>
                        <span></span>
                        <span></span>
                    </div>
                </div>
            </div>
        </div>
    `);
    scrollChatToBottom();
    
    // 模拟AI回复（在实际应用中，这里应该调用API）
    setTimeout(function() {
        // 移除正在输入指示器
        $('#typing-indicator-wrapper').remove();
        
        // 添加AI回复
        $('#chat-messages').append(`
            <div class="message-wrapper">
                <div class="message message-bot">
                    <div class="message-header">
                        <div class="message-avatar">
                            <i class="fas fa-robot"></i>
                        </div>
                        <div class="message-info">
                            <div class="message-sender">机勘院智能助手</div>
                            <div class="message-time">${timeStr}</div>
                        </div>
                    </div>
                    <div class="message-content">
                        <p>感谢您的提问。根据您询问的内容"${messageText}"，我可以提供以下信息：</p>
                        <p>这是一个关于机勘院专业内容的模拟回复。在实际应用中，这里将通过DeepSeek API返回真实的回答内容。</p>
                        <div class="message-references mt-2">
                            <div class="references-title">引用文档</div>
                            <div class="reference-item">
                                <i class="fas fa-file-pdf text-danger me-2"></i>
                                <a href="#">道路勘察技术规范.pdf</a>
                                <span class="badge bg-light text-dark ms-2">引用：第35页</span>
                            </div>
                        </div>
                    </div>
                    <div class="message-actions">
                        <button class="btn btn-sm btn-link btn-message-action" title="复制"><i class="fas fa-copy"></i></button>
                        <button class="btn btn-sm btn-link btn-message-action" title="收藏"><i class="far fa-star"></i></button>
                        <button class="btn btn-sm btn-link btn-message-action" title="反馈"><i class="fas fa-thumbs-up"></i></button>
                    </div>
                </div>
            </div>
        `);
        
        // 更新新的建议
        updateSuggestions(messageText);
        
        // 更新聊天统计
        updateChatStats();
        
        // 滚动到底部
        scrollChatToBottom();
    }, 1500);
}

/**
 * 更新智能建议
 * @param {string} lastMessage - 上一条消息
 */
function updateSuggestions(lastMessage) {
    // 根据上一条消息生成相关建议
    let suggestions = [];
    
    if (lastMessage.includes('道路') || lastMessage.includes('勘察')) {
        suggestions = ['道路勘察标准规范有哪些？', '如何提高道路勘察精度？', '道路勘察报告格式'];
    } else if (lastMessage.includes('工程') || lastMessage.includes('设计')) {
        suggestions = ['工程设计软件推荐', '工程项目管理最佳实践', '设计方案审核流程'];
    } else if (lastMessage.includes('地质') || lastMessage.includes('测量')) {
        suggestions = ['地质测量现代技术', '地质数据分析方法', '常见地质结构特征'];
    } else {
        suggestions = ['机勘院各部门职能', '勘测技术发展趋势', '如何提高工作效率'];
    }
    
    // 更新建议UI
    const suggestionsContainer = $('#chat-suggestions');
    suggestionsContainer.empty();
    
    suggestions.forEach(function(suggestion) {
        suggestionsContainer.append(`<button class="suggestion-item">${suggestion}</button>`);
    });
    
    // 重新绑定点击事件
    $('.suggestion-item').on('click', function() {
        $('#chat-input-text').val($(this).text());
        sendChatMessage();
    });
}

/**
 * 更新聊天统计
 */
function updateChatStats() {
    const userMessages = $('.message-user').length;
    const botMessages = $('.message-bot').not('.typing').length;
    const totalTurns = Math.min(userMessages, botMessages);
    
    $('#chatTurns').text(totalTurns);
    $('#userMessages').text(userMessages);
    $('#botMessages').text(botMessages);
}

/**
 * 导出聊天历史
 */
function exportChatHistory() {
    // 获取所有消息
    let chatContent = '';
    
    // 添加标题
    chatContent += '机勘院智能会话记录\n';
    chatContent += '时间：' + new Date().toLocaleString() + '\n\n';
    
    // 遍历消息
    $('.message').each(function() {
        const isBot = $(this).hasClass('message-bot') && !$(this).hasClass('typing');
        const isUser = $(this).hasClass('message-user');
        
        if (isBot || isUser) {
            const sender = isBot ? '机勘院智能助手' : '您';
            const time = $(this).find('.message-time').text();
            const content = $(this).find('.message-content p').map(function() {
                return $(this).text();
            }).get().join('\n');
            
            chatContent += `[${time}] ${sender}:\n${content}\n\n`;
        }
    });
    
    // 创建下载链接
    const blob = new Blob([chatContent], { type: 'text/plain' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = '机勘院智能会话_' + new Date().toISOString().slice(0, 10) + '.txt';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
}

/**
 * 重置聊天
 */
function resetChat() {
    // 清空聊天消息
    $('#chat-messages').html(`
        <div class="chat-date-divider">
            <span>今天</span>
        </div>
        
        <div class="message-wrapper">
            <div class="message message-bot">
                <div class="message-header">
                    <div class="message-avatar">
                        <i class="fas fa-robot"></i>
                    </div>
                    <div class="message-info">
                        <div class="message-sender">机勘院智能助手</div>
                        <div class="message-time">${new Date().getHours().toString().padStart(2, '0')}:${new Date().getMinutes().toString().padStart(2, '0')}</div>
                    </div>
                </div>
                <div class="message-content">
                    <p>您好，我是机勘院智能业务系统助手，很高兴为您服务。请问有什么可以帮助您的？</p>
                    <p>您可以询问我关于道路勘察、地质勘测、工程设计等方面的问题。</p>
                </div>
                <div class="message-actions">
                    <button class="btn btn-sm btn-link btn-message-action" title="复制"><i class="fas fa-copy"></i></button>
                </div>
            </div>
        </div>
    `);
    
    // 更新统计数据
    updateChatStats();
    
    // 恢复默认建议
    $('#chat-suggestions').html(`
        <button class="suggestion-item">道路勘察流程</button>
        <button class="suggestion-item">工程设计标准</button>
        <button class="suggestion-item">地质勘测报告格式</button>
    `);
    
    // 重新绑定建议点击事件
    $('.suggestion-item').on('click', function() {
        $('#chat-input-text').val($(this).text());
        sendChatMessage();
    });
}

/**
 * 滚动聊天窗口到底部
 */
function scrollChatToBottom() {
    const chatMessages = document.getElementById('chat-messages');
    chatMessages.scrollTop = chatMessages.scrollHeight;
}

/**
 * 加载文件库页面
 */
function loadFilePage() {
    $('#main-content').html(`
        <div class="row mb-3">
            <div class="col-md-6">
                <h3>文件库管理</h3>
            </div>
            <div class="col-md-6 text-end">
                <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadFileModal">
                    <i class="fas fa-upload"></i> 上传文件
                </button>
            </div>
        </div>
        
        <div class="row mb-3">
            <div class="col">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="搜索文件...">
                    <button class="btn btn-outline-secondary" type="button">搜索</button>
                </div>
            </div>
            <div class="col-auto">
                <select class="form-select">
                    <option value="all">所有文件</option>
                    <option value="doc">文档</option>
                    <option value="image">图片</option>
                    <option value="other">其他</option>
                </select>
            </div>
        </div>
        
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>文件名</th>
                        <th>类型</th>
                        <th>大小</th>
                        <th>上传日期</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>机勘院项目报告.docx</td>
                        <td>Word文档</td>
                        <td>256 KB</td>
                        <td>2025-03-01</td>
                        <td>
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-danger">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td>道路勘察数据.xlsx</td>
                        <td>Excel表格</td>
                        <td>512 KB</td>
                        <td>2025-02-28</td>
                        <td>
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-danger">删除</button>
                        </td>
                    </tr>
                    <tr>
                        <td>工程现场照片.jpg</td>
                        <td>图片</td>
                        <td>1.2 MB</td>
                        <td>2025-02-27</td>
                        <td>
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-danger">删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        
        <!-- 上传文件模态框 -->
        <div class="modal fade" id="uploadFileModal" tabindex="-1" aria-labelledby="uploadFileModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="uploadFileModalLabel">上传文件</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="mb-3">
                                <label for="fileUpload" class="form-label">选择文件</label>
                                <input class="form-control" type="file" id="fileUpload">
                            </div>
                            <div class="mb-3">
                                <label for="fileDescription" class="form-label">文件描述</label>
                                <textarea class="form-control" id="fileDescription" rows="3"></textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary">上传</button>
                    </div>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载知识库页面
 */
function loadKnowledgePage() {
    $('#main-content').html(`
        <div class="row mb-3">
            <div class="col-md-6">
                <h3>知识库管理</h3>
            </div>
            <div class="col-md-6 text-end">
                <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addKnowledgeModal">
                    <i class="fas fa-plus"></i> 添加知识
                </button>
            </div>
        </div>
        
        <div class="row mb-3">
            <div class="col">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="搜索知识...">
                    <button class="btn btn-outline-secondary" type="button">搜索</button>
                </div>
            </div>
            <div class="col-auto">
                <select class="form-select">
                    <option value="all">所有分类</option>
                    <option value="road">道路勘察</option>
                    <option value="geology">地质勘测</option>
                    <option value="engineering">工程设计</option>
                </select>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-4">
                <div class="card card-library">
                    <div class="card-body">
                        <h5 class="card-title">道路勘察技术规范</h5>
                        <p class="card-text">包含道路勘察的技术标准、方法和流程文档。</p>
                        <div class="d-flex justify-content-between">
                            <span class="badge bg-info">道路勘察</span>
                            <small class="text-muted">更新于 2025-02-15</small>
                        </div>
                        <div class="mt-3">
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-secondary">编辑</button>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-md-4">
                <div class="card card-library">
                    <div class="card-body">
                        <h5 class="card-title">地质勘测报告模板</h5>
                        <p class="card-text">标准地质勘测报告的模板及填写指南。</p>
                        <div class="d-flex justify-content-between">
                            <span class="badge bg-warning">地质勘测</span>
                            <small class="text-muted">更新于 2025-01-30</small>
                        </div>
                        <div class="mt-3">
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-secondary">编辑</button>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-md-4">
                <div class="card card-library">
                    <div class="card-body">
                        <h5 class="card-title">工程设计基础知识</h5>
                        <p class="card-text">包含工程设计必备的基础理论和应用方法。</p>
                        <div class="d-flex justify-content-between">
                            <span class="badge bg-success">工程设计</span>
                            <small class="text-muted">更新于 2025-01-20</small>
                        </div>
                        <div class="mt-3">
                            <button class="btn btn-sm btn-outline-primary">查看</button>
                            <button class="btn btn-sm btn-outline-secondary">编辑</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 添加知识模态框 -->
        <div class="modal fade" id="addKnowledgeModal" tabindex="-1" aria-labelledby="addKnowledgeModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="addKnowledgeModalLabel">添加知识</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="mb-3">
                                <label for="knowledgeTitle" class="form-label">标题</label>
                                <input type="text" class="form-control" id="knowledgeTitle">
                            </div>
                            <div class="mb-3">
                                <label for="knowledgeCategory" class="form-label">分类</label>
                                <select class="form-select" id="knowledgeCategory">
                                    <option value="road">道路勘察</option>
                                    <option value="geology">地质勘测</option>
                                    <option value="engineering">工程设计</option>
                                    <option value="other">其他</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="knowledgeContent" class="form-label">内容</label>
                                <textarea class="form-control" id="knowledgeContent" rows="10"></textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary">保存</button>
                    </div>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载数据分析页面
 */
function loadDataAnalyticsPage() {
    $('#main-content').html(`
        <div class="deepseek-page-header">
            <h4>数据分析</h4>
            <p class="text-muted">深入分析系统数据，优化决策制定</p>
        </div>
        
        <div class="row g-3">
            <div class="col-lg-4">
                <div class="deepseek-card mb-3">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">分析周期</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="mb-3">
                            <label class="form-label">选择时间范围</label>
                            <select class="form-select" id="timeRange">
                                <option value="7">最近7天</option>
                                <option value="30" selected>最近30天</option>
                                <option value="90">最近90天</option>
                                <option value="365">过去一年</option>
                                <option value="custom">自定义范围</option>
                            </select>
                        </div>
                        
                        <div id="customDateRange" class="row g-2" style="display: none;">
                            <div class="col-6">
                                <label class="form-label">开始日期</label>
                                <input type="date" class="form-control" id="startDate">
                            </div>
                            <div class="col-6">
                                <label class="form-label">结束日期</label>
                                <input type="date" class="form-control" id="endDate">
                            </div>
                        </div>
                        
                        <div class="mt-3">
                            <button class="btn btn-primary w-100" id="applyDateRange">应用</button>
                        </div>
                    </div>
                </div>
                
                <div class="deepseek-card">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">数据筛选</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="mb-3">
                            <label class="form-label">用户组</label>
                            <select class="form-select" id="userGroup">
                                <option value="all" selected>所有用户</option>
                                <option value="admin">管理员</option>
                                <option value="user">普通用户</option>
                                <option value="guest">访客</option>
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label class="form-label">数据类型</label>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" value="files" id="filesCheck" checked>
                                <label class="form-check-label" for="filesCheck">文件</label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" value="chats" id="chatsCheck" checked>
                                <label class="form-check-label" for="chatsCheck">会话</label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" value="knowledge" id="knowledgeCheck" checked>
                                <label class="form-check-label" for="knowledgeCheck">知识库</label>
                            </div>
                        </div>
                        
                        <div class="mt-3">
                            <button class="btn btn-outline-primary w-100" id="applyFilters">应用筛选</button>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-8">
                <!-- 趋势图 -->
                <div class="deepseek-card mb-3">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">使用趋势</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="chart-container" id="usageTrendChart">
                            <div class="deepseek-loading">
                                <div class="loading-spinner"></div>
                                <div class="loading-text">加载数据...</div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 分布图 -->
                <div class="row g-3">
                    <div class="col-md-6">
                        <div class="deepseek-card">
                            <div class="deepseek-card-header">
                                <h5 class="deepseek-card-title">文件类型分布</h5>
                            </div>
                            <div class="deepseek-card-body">
                                <div class="chart-container" id="fileTypeChart">
                                    <div class="deepseek-loading">
                                        <div class="loading-spinner"></div>
                                        <div class="loading-text">加载数据...</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-md-6">
                        <div class="deepseek-card">
                            <div class="deepseek-card-header">
                                <h5 class="deepseek-card-title">用户活跃度</h5>
                            </div>
                            <div class="deepseek-card-body">
                                <div class="chart-container" id="userActivityChart">
                                    <div class="deepseek-loading">
                                        <div class="loading-spinner"></div>
                                        <div class="loading-text">加载数据...</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 详情表格 -->
                <div class="deepseek-card mt-3">
                    <div class="deepseek-card-header d-flex justify-content-between align-items-center">
                        <h5 class="deepseek-card-title mb-0">详细数据</h5>
                        <div>
                            <button class="btn btn-sm btn-outline-primary me-2" id="refreshData">
                                <i class="fas fa-sync-alt me-1"></i>刷新
                            </button>
                            <button class="btn btn-sm btn-outline-success" id="exportData">
                                <i class="fas fa-file-export me-1"></i>导出
                            </button>
                        </div>
                    </div>
                    <div class="deepseek-card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-hover mb-0">
                                <thead>
                                    <tr>
                                        <th>日期</th>
                                        <th>用户数</th>
                                        <th>会话数</th>
                                        <th>文件数</th>
                                        <th>知识条目</th>
                                        <th>存储用量</th>
                                    </tr>
                                </thead>
                                <tbody id="analyticsTable">
                                    <tr>
                                        <td>2023-03-01</td>
                                        <td>42</td>
                                        <td>185</td>
                                        <td>76</td>
                                        <td>412</td>
                                        <td>2.4 GB</td>
                                    </tr>
                                    <tr>
                                        <td>2023-02-28</td>
                                        <td>38</td>
                                        <td>162</td>
                                        <td>63</td>
                                        <td>408</td>
                                        <td>2.3 GB</td>
                                    </tr>
                                    <tr>
                                        <td>2023-02-27</td>
                                        <td>41</td>
                                        <td>178</td>
                                        <td>59</td>
                                        <td>402</td>
                                        <td>2.2 GB</td>
                                    </tr>
                                    <tr>
                                        <td>2023-02-26</td>
                                        <td>36</td>
                                        <td>145</td>
                                        <td>51</td>
                                        <td>395</td>
                                        <td>2.1 GB</td>
                                    </tr>
                                    <tr>
                                        <td>2023-02-25</td>
                                        <td>37</td>
                                        <td>158</td>
                                        <td>48</td>
                                        <td>390</td>
                                        <td>2.0 GB</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="deepseek-card-footer d-flex justify-content-between align-items-center">
                        <div class="text-muted small">显示 1-5 条，共 30 条</div>
                        <div class="deepseek-pagination-actions">
                            <button class="deepseek-pagination-button disabled" disabled>
                                <i class="fas fa-chevron-left"></i>
                            </button>
                            <button class="deepseek-pagination-button active">1</button>
                            <button class="deepseek-pagination-button">2</button>
                            <button class="deepseek-pagination-button">3</button>
                            <button class="deepseek-pagination-button">
                                <i class="fas fa-chevron-right"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    `);
    
    // 绑定日期范围选择事件
    $('#timeRange').on('change', function() {
        if ($(this).val() === 'custom') {
            $('#customDateRange').show();
        } else {
            $('#customDateRange').hide();
        }
    });
    
    // 模拟图表加载
    setTimeout(function() {
        // 这里可以添加实际的图表初始化代码
        // 例如使用Chart.js或ECharts等库
        $('#usageTrendChart, #fileTypeChart, #userActivityChart').empty();
        $('#usageTrendChart').html('<img src="https://via.placeholder.com/800x300?text=使用趋势图" class="img-fluid" alt="使用趋势图">');
        $('#fileTypeChart').html('<img src="https://via.placeholder.com/400x200?text=文件类型分布图" class="img-fluid" alt="文件类型分布图">');
        $('#userActivityChart').html('<img src="https://via.placeholder.com/400x200?text=用户活跃度图" class="img-fluid" alt="用户活跃度图">');
    }, 1500);
}

/**
 * 加载帮助中心页面
 */
function loadHelpPage() {
    $('#main-content').html(`
        <div class="deepseek-page-header">
            <h4>帮助中心</h4>
            <p class="text-muted">获取系统使用指南和常见问题解答</p>
        </div>
        
        <div class="row g-3">
            <div class="col-lg-4">
                <div class="deepseek-card mb-3">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">快速导航</h5>
                    </div>
                    <div class="deepseek-card-body p-0">
                        <div class="list-group list-group-flush">
                            <a href="#getting-started" class="list-group-item list-group-item-action d-flex align-items-center">
                                <i class="fas fa-play-circle me-3 text-primary"></i>
                                <span>快速入门</span>
                            </a>
                            <a href="#file-management" class="list-group-item list-group-item-action d-flex align-items-center">
                                <i class="fas fa-folder me-3 text-primary"></i>
                                <span>文件管理</span>
                            </a>
                            <a href="#ai-chat" class="list-group-item list-group-item-action d-flex align-items-center">
                                <i class="fas fa-comments me-3 text-primary"></i>
                                <span>智能会话</span>
                            </a>
                            <a href="#knowledge-base" class="list-group-item list-group-item-action d-flex align-items-center">
                                <i class="fas fa-book me-3 text-primary"></i>
                                <span>知识库</span>
                            </a>
                            <a href="#faqs" class="list-group-item list-group-item-action d-flex align-items-center">
                                <i class="fas fa-question-circle me-3 text-primary"></i>
                                <span>常见问题</span>
                            </a>
                        </div>
                    </div>
                </div>
                
                <div class="deepseek-card">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">联系支持</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="deepseek-info-card mb-3">
                            <div class="info-icon">
                                <i class="fas fa-envelope"></i>
                            </div>
                            <div class="info-content">
                                <div class="info-title">电子邮件</div>
                                <div class="info-subtitle">support@jk.com.cn</div>
                            </div>
                        </div>
                        
                        <div class="deepseek-info-card mb-3">
                            <div class="info-icon">
                                <i class="fas fa-phone-alt"></i>
                            </div>
                            <div class="info-content">
                                <div class="info-title">服务热线</div>
                                <div class="info-subtitle">400-888-XXXX</div>
                            </div>
                        </div>
                        
                        <div class="deepseek-info-card">
                            <div class="info-icon">
                                <i class="fas fa-comments"></i>
                            </div>
                            <div class="info-content">
                                <div class="info-title">在线客服</div>
                                <div class="info-subtitle">工作日 9:00-18:00</div>
                            </div>
                            <div class="info-actions">
                                <button class="btn btn-sm btn-primary">咨询</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-8">
                <!-- 快速入门 -->
                <div class="deepseek-card mb-3" id="getting-started">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">快速入门</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <div class="mb-4">
                            <h6 class="fw-bold mb-3">系统概述</h6>
                            <p>机勘院智能业务系统是一个智能化工作平台，集成了文件管理、智能会话、知识库等功能，旨在提升团队协作效率和信息管理能力。</p>
                            
                            <div class="deepseek-steps mt-4 mb-4">
                                <div class="deepseek-step completed">
                                    <div class="deepseek-step-icon">
                                        <i class="fas fa-check"></i>
                                    </div>
                                    <div class="deepseek-step-label">注册登录</div>
                                </div>
                                <div class="deepseek-step completed">
                                    <div class="deepseek-step-icon">
                                        <i class="fas fa-check"></i>
                                    </div>
                                    <div class="deepseek-step-label">完善资料</div>
                                </div>
                                <div class="deepseek-step active">
                                    <div class="deepseek-step-icon">
                                        <i class="fas fa-sync-alt"></i>
                                    </div>
                                    <div class="deepseek-step-label">功能探索</div>
                                </div>
                                <div class="deepseek-step">
                                    <div class="deepseek-step-icon">
                                        <i class="fas fa-star"></i>
                                    </div>
                                    <div class="deepseek-step-label">高级应用</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <h6 class="fw-bold mb-3">快速上手视频</h6>
                            <div class="ratio ratio-16x9">
                                <img src="https://via.placeholder.com/640x360?text=系统使用教程视频" class="img-fluid" alt="快速入门教程">
                            </div>
                        </div>
                        
                        <div class="mb-0">
                            <h6 class="fw-bold mb-3">常用功能</h6>
                            <div class="row g-3">
                                <div class="col-md-6">
                                    <div class="card h-100">
                                        <div class="card-body">
                                            <h6 class="card-title">
                                                <i class="fas fa-file-upload me-2 text-primary"></i>上传文件
                                            </h6>
                                            <p class="card-text small">快速上传文档、图片等各类文件，支持拖放操作和批量上传。</p>
                                            <a href="#file-management" class="btn btn-sm btn-outline-primary">查看详情</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card h-100">
                                        <div class="card-body">
                                            <h6 class="card-title">
                                                <i class="fas fa-comment-dots me-2 text-primary"></i>智能对话
                                            </h6>
                                            <p class="card-text small">与AI助手进行自然语言交流，快速获取信息和解决问题。</p>
                                            <a href="#ai-chat" class="btn btn-sm btn-outline-primary">查看详情</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 文件管理 -->
                <div class="deepseek-card mb-3" id="file-management">
                    <div class="deepseek-card-header">
                        <h5 class="deepseek-card-title">文件管理</h5>
                    </div>
                    <div class="deepseek-card-body">
                        <p>文件管理模块提供了直观的界面，帮助您高效地组织、存储和共享各类文件资料。</p>
                        
                        <div class="accordion mt-3" id="fileAccordion">
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="headingOne">
                                    <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                        如何上传文件？
                                    </button>
                                </h2>
                                <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#fileAccordion">
                                    <div class="accordion-body">
                                        <p>您可以通过以下方式上传文件：</p>
                                        <ol>
                                            <li>点击左侧导航栏的"文件库"，进入文件管理页面</li>
                                            <li>点击"上传文件"按钮，选择要上传的文件</li>
                                            <li>或者直接将文件拖放到上传区域</li>
                                            <li>等待上传完成，文件将显示在文件列表中</li>
                                        </ol>
                                    </div>
                                </div>
                            </div>
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="headingTwo">
                                    <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                        如何组织和管理文件？
                                    </button>
                                </h2>
                                <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#fileAccordion">
                                    <div class="accordion-body">
                                        <p>您可以使用以下功能来组织和管理文件：</p>
                                        <ul>
                                            <li>创建文件夹：点击"新建文件夹"按钮，输入文件夹名称</li>
                                            <li>移动文件：选择文件，点击"移动"或拖放到目标文件夹</li>
                                            <li>重命名：右键点击文件或文件夹，选择"重命名"</li>
                                            <li>添加标签：选择文件，点击"添加标签"，便于后续快速筛选</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div class="accordion-item">
                                <h2 class="accordion-header" id="headingThree">
                                    <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                                        如何共享文件？
                                    </button>
                                </h2>
                                <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#fileAccordion">
                                    <div class="accordion-body">
                                        <p>共享文件的步骤：</p>
                                        <ol>
                                            <li>选择要共享的文件，点击"共享"按钮</li>
                                            <li>在弹出的对话框中，输入接收人的姓名或邮箱</li>
                                            <li>设置权限：只读、可编辑或完全控制</li>
                                            <li>点击"确认"完成共享</li>
                                        </ol>
                                        <p>您还可以生成共享链接，设置链接有效期和访问密码。</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 其他帮助内容可以根据实际需求继续添加 -->
                
            </div>
        </div>
    `);
} 

/**
 * 加载系统管理页面
 * @param {string} action - 子菜单操作
 */
function loadSystemPage(action) {
    console.log(`加载系统管理页面: ${action}`);
    
    // 加载系统管理页面内容框架
    $('#main-content').html(`
        <div class="container-fluid py-4">
            <!-- 主要内容区域 - 根据action加载 -->
            <div id="system-content"></div>
        </div>
    `);
    
    // 动态加载系统管理的CSS文件
    if (!document.getElementById('system-css')) {
        $('head').append('<link id="system-css" href="css/system.css" rel="stylesheet">');
    }
    
    // 直接加载对应内容 - 不再尝试加载system.js
    loadSystemContent(action);
}

/**
 * 加载系统管理JS
 * @param {string} action - 子菜单操作
 */
function loadSystemJS(action) {
    // 检查system.js脚本是否已加载
    if (typeof window.loadTabContent !== 'function') {
        // 动态加载system.js
        $.getScript('js/system.js')
            .done(function() {
                console.log('系统管理JS加载成功');
                // 初始化系统资源图表（如果有）
                if (typeof window.initSystemResourceChart === 'function') {
                    window.initSystemResourceChart();
                }
                // 加载对应内容
                setTimeout(function() {
                    loadSystemContent(action);
                }, 100);
            })
            .fail(function() {
                console.error('系统管理JS加载失败');
                $('#system-content').html('<div class="alert alert-danger">系统管理模块加载失败，请刷新页面重试</div>');
            });
    } else {
        // 如果system.js已加载，直接加载内容
        loadSystemContent(action);
    }
}

/**
 * 初始化系统资源图表
 */
function initSystemResourceChart() {
    // 在这里不实现完整功能，留给system.js处理
    console.log('系统资源图表初始化');
}

/**
 * 加载系统管理内容
 * @param {string} action - 子菜单操作
 */
function loadSystemContent(action) {
    console.log('加载系统管理内容:', action);
    
    // 根据子菜单操作加载对应内容
    switch(action) {
        case 'userManagement':
            loadUserManagementContent();
            break;
        case 'rolesPermissions':
            loadRolesPermissionsContent();
            break;
        case 'systemLogs':
            loadSystemLogsContent();
            break;
        case 'dataBackup':
            loadDataBackupContent();
            break;
        case 'aiConfig':
            loadAiConfigContent();
            break;
        case 'systemConfig':
            loadSystemConfigContent();
            break;
        default:
            loadSystemConfigContent(); // 默认加载系统配置
    }
}

/**
 * 加载用户管理内容
 */
function loadUserManagementContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">用户管理</h5>
                <button class="btn btn-primary" id="addUserBtn">
                    <i class="fas fa-plus me-1"></i>添加用户
                </button>
            </div>
            <div class="card-body">
                <div class="row g-3 mb-3">
                    <div class="col-md-4">
                        <div class="input-group">
                            <span class="input-group-text"><i class="fas fa-search"></i></span>
                            <input type="text" class="form-control" placeholder="搜索用户...">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <select class="form-select" id="roleFilter">
                            <option value="all">所有角色</option>
                            <option value="admin">管理员</option>
                            <option value="manager">项目经理</option>
                            <option value="engineer">工程师</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <select class="form-select" id="departmentFilter">
                            <option value="all">所有部门</option>
                            <option value="system">系统管理部</option>
                            <option value="project">项目管理部</option>
                            <option value="road">道路勘察部</option>
                        </select>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table system-table">
                        <thead>
                            <tr>
                                <th>用户信息</th>
                                <th>角色</th>
                                <th>部门</th>
                                <th>上次登录</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <div class="d-flex align-items-center">
                                        <div class="deepseek-avatar me-3">A</div>
                                        <div>
                                            <div class="fw-bold">admin</div>
                                            <div class="small text-muted">admin@example.com</div>
                                        </div>
                                    </div>
                                </td>
                                <td>管理员</td>
                                <td>系统管理部</td>
                                <td>2025-03-02 12:30:45</td>
                                <td><span class="badge bg-success">活跃</span></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-eye"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-ban"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div class="d-flex align-items-center">
                                        <div class="deepseek-avatar me-3">E</div>
                                        <div>
                                            <div class="fw-bold">engineer01</div>
                                            <div class="small text-muted">engineer01@example.com</div>
                                        </div>
                                    </div>
                                </td>
                                <td>工程师</td>
                                <td>道路勘察部</td>
                                <td>2025-03-01 09:15:22</td>
                                <td><span class="badge bg-success">活跃</span></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-eye"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-ban"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载角色权限内容
 */
function loadRolesPermissionsContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">角色权限管理</h5>
                <button class="btn btn-primary">
                    <i class="fas fa-plus me-1"></i>添加角色
                </button>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="list-group">
                            <a href="#" class="list-group-item list-group-item-action active">
                                <div class="d-flex w-100 justify-content-between">
                                    <h6 class="mb-1">管理员</h6>
                                    <small>用户数: 3</small>
                                </div>
                                <p class="mb-1">系统最高权限角色</p>
                            </a>
                            <a href="#" class="list-group-item list-group-item-action">
                                <div class="d-flex w-100 justify-content-between">
                                    <h6 class="mb-1">项目经理</h6>
                                    <small>用户数: 8</small>
                                </div>
                                <p class="mb-1">项目管理与审批权限</p>
                            </a>
                            <a href="#" class="list-group-item list-group-item-action">
                                <div class="d-flex w-100 justify-content-between">
                                    <h6 class="mb-1">工程师</h6>
                                    <small>用户数: 24</small>
                                </div>
                                <p class="mb-1">技术操作与文档权限</p>
                            </a>
                        </div>
                    </div>
                    <div class="col-md-8">
                        <h6 class="mb-3">管理员权限设置</h6>
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>功能模块</th>
                                        <th>查看</th>
                                        <th>新增</th>
                                        <th>编辑</th>
                                        <th>删除</th>
                                        <th>审批</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>用户管理</td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                    </tr>
                                    <tr>
                                        <td>文件管理</td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                    </tr>
                                    <tr>
                                        <td>知识库</td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                        <td><input type="checkbox" class="form-check-input" checked disabled></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载系统日志内容
 */
function loadSystemLogsContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">系统日志</h5>
                <div>
                    <button class="btn btn-outline-primary me-2">
                        <i class="fas fa-download me-1"></i>导出日志
                    </button>
                    <button class="btn btn-outline-secondary">
                        <i class="fas fa-filter me-1"></i>筛选
                    </button>
                </div>
            </div>
            <div class="card-body">
                <div class="row g-3 mb-3">
                    <div class="col-md-3">
                        <select class="form-select">
                            <option>所有级别</option>
                            <option>错误</option>
                            <option>警告</option>
                            <option>信息</option>
                            <option>调试</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <select class="form-select">
                            <option>所有模块</option>
                            <option>用户认证</option>
                            <option>文件系统</option>
                            <option>数据库</option>
                            <option>API</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <div class="input-group">
                            <input type="date" class="form-control">
                            <span class="input-group-text">至</span>
                            <input type="date" class="form-control">
                        </div>
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-primary w-100">应用</button>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table system-table">
                        <thead>
                            <tr>
                                <th>时间</th>
                                <th>级别</th>
                                <th>模块</th>
                                <th>内容</th>
                                <th>IP</th>
                                <th>用户</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>2025-03-02 14:32:51</td>
                                <td><span class="badge bg-danger">错误</span></td>
                                <td>数据库</td>
                                <td>无法连接到数据库服务器</td>
                                <td>192.168.1.10</td>
                                <td>system</td>
                            </tr>
                            <tr>
                                <td>2025-03-02 14:30:22</td>
                                <td><span class="badge bg-warning">警告</span></td>
                                <td>文件系统</td>
                                <td>存储空间不足，低于20%</td>
                                <td>192.168.1.10</td>
                                <td>system</td>
                            </tr>
                            <tr>
                                <td>2025-03-02 14:28:10</td>
                                <td><span class="badge bg-info">信息</span></td>
                                <td>用户认证</td>
                                <td>用户admin登录成功</td>
                                <td>192.168.1.42</td>
                                <td>admin</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载数据备份内容
 */
function loadDataBackupContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">数据备份</h5>
                <button class="btn btn-primary">
                    <i class="fas fa-plus me-1"></i>创建备份
                </button>
            </div>
            <div class="card-body">
                <div class="alert alert-info">
                    <i class="fas fa-info-circle me-2"></i>
                    <span>上次备份时间: <strong>2025-03-01 03:00:00</strong> | 备份状态: <strong>成功</strong> | 下次自动备份: <strong>2025-03-03 03:00:00</strong></span>
                </div>
                
                <div class="table-responsive">
                    <table class="table system-table">
                        <thead>
                            <tr>
                                <th>备份ID</th>
                                <th>备份时间</th>
                                <th>文件大小</th>
                                <th>备份类型</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>BK202503010300</td>
                                <td>2025-03-01 03:00:00</td>
                                <td>1.2 GB</td>
                                <td>自动</td>
                                <td><span class="badge bg-success">成功</span></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-primary">
                                            <i class="fas fa-download"></i>
                                        </button>
                                        <button class="btn btn-outline-warning">
                                            <i class="fas fa-undo-alt"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>BK202502280300</td>
                                <td>2025-02-28 03:00:00</td>
                                <td>1.1 GB</td>
                                <td>自动</td>
                                <td><span class="badge bg-success">成功</span></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-primary">
                                            <i class="fas fa-download"></i>
                                        </button>
                                        <button class="btn btn-outline-warning">
                                            <i class="fas fa-undo-alt"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>BK202502271425</td>
                                <td>2025-02-27 14:25:10</td>
                                <td>1.0 GB</td>
                                <td>手动</td>
                                <td><span class="badge bg-success">成功</span></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-primary">
                                            <i class="fas fa-download"></i>
                                        </button>
                                        <button class="btn btn-outline-warning">
                                            <i class="fas fa-undo-alt"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载AI配置内容
 */
function loadAiConfigContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">智能业务配置</h5>
                <button class="btn btn-primary" id="addModelBtn">
                    <i class="fas fa-plus me-1"></i>添加模型
                </button>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table system-table">
                        <thead>
                            <tr>
                                <th>模型名称</th>
                                <th>类型</th>
                                <th>API密钥</th>
                                <th>状态</th>
                                <th>最大Tokens</th>
                                <th>温度</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>DeepSeek-Coder</td>
                                <td>代码生成</td>
                                <td>······························</td>
                                <td><span class="badge bg-success">已启用</span></td>
                                <td>8192</td>
                                <td>0.7</td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-vial"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-ban"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>DeepSeek-Vision</td>
                                <td>图像分析</td>
                                <td>······························</td>
                                <td><span class="badge bg-success">已启用</span></td>
                                <td>4096</td>
                                <td>0.5</td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-vial"></i>
                                        </button>
                                        <button class="btn btn-outline-danger">
                                            <i class="fas fa-ban"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>OpenAI-GPT-4</td>
                                <td>文本分析</td>
                                <td>······························</td>
                                <td><span class="badge bg-secondary">已禁用</span></td>
                                <td>16384</td>
                                <td>0.8</td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-outline-secondary">
                                            <i class="fas fa-vial"></i>
                                        </button>
                                        <button class="btn btn-outline-success">
                                            <i class="fas fa-check"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    `);
}

/**
 * 加载系统配置内容
 */
function loadSystemConfigContent() {
    $('#system-content').html(`
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">系统基本配置</h5>
                <button class="btn btn-primary" id="saveConfigBtn">
                    <i class="fas fa-save me-1"></i>保存设置
                </button>
            </div>
            <div class="card-body">
                <form id="systemConfigForm">
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="systemName" class="form-label">系统名称</label>
                                <input type="text" class="form-control" id="systemName" value="机勘院智能业务系统">
                            </div>
                            <div class="mb-3">
                                <label for="systemLogo" class="form-label">系统Logo</label>
                                <div class="input-group">
                                    <input type="file" class="form-control" id="systemLogo">
                                    <button class="btn btn-outline-secondary" type="button">上传</button>
                                </div>
                                <div class="form-text">推荐尺寸: 200x60 像素</div>
                            </div>
                            <div class="mb-3">
                                <label for="systemVersion" class="form-label">系统版本</label>
                                <input type="text" class="form-control" id="systemVersion" value="2.5.0" readonly>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="companyName" class="form-label">公司名称</label>
                                <input type="text" class="form-control" id="companyName" value="机械工业勘察设计研究院有限公司">
                            </div>
                            <div class="mb-3">
                                <label for="contactEmail" class="form-label">系统管理员邮箱</label>
                                <input type="email" class="form-control" id="contactEmail" value="admin@example.com">
                            </div>
                            <div class="mb-3">
                                <label for="systemLanguage" class="form-label">系统语言</label>
                                <select class="form-select" id="systemLanguage">
                                    <option value="zh-CN" selected>中文(简体)</option>
                                    <option value="en-US">English (US)</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <h6 class="mb-3">系统功能设置</h6>
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableChat" checked>
                                <label class="form-check-label" for="enableChat">启用智能会话</label>
                            </div>
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableFileSystem" checked>
                                <label class="form-check-label" for="enableFileSystem">启用文件库</label>
                            </div>
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableKnowledge" checked>
                                <label class="form-check-label" for="enableKnowledge">启用知识库</label>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableDataAnalytics" checked>
                                <label class="form-check-label" for="enableDataAnalytics">启用数据分析</label>
                            </div>
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableNotifications" checked>
                                <label class="form-check-label" for="enableNotifications">启用系统通知</label>
                            </div>
                            <div class="form-check form-switch mb-3">
                                <input class="form-check-input" type="checkbox" id="enableDarkMode" checked>
                                <label class="form-check-label" for="enableDarkMode">启用暗黑模式切换</label>
                            </div>
                        </div>
                    </div>
                    
                    <h6 class="mb-3">系统参数配置</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="sessionTimeout" class="form-label">会话超时时间(分钟)</label>
                                <input type="number" class="form-control" id="sessionTimeout" value="30">
                            </div>
                            <div class="mb-3">
                                <label for="maxUploadSize" class="form-label">最大上传文件大小(MB)</label>
                                <input type="number" class="form-control" id="maxUploadSize" value="50">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="dataRetentionDays" class="form-label">数据保留天数</label>
                                <input type="number" class="form-control" id="dataRetentionDays" value="180">
                            </div>
                            <div class="mb-3">
                                <label for="backupSchedule" class="form-label">自动备份频率</label>
                                <select class="form-select" id="backupSchedule">
                                    <option value="daily">每日</option>
                                    <option value="weekly" selected>每周</option>
                                    <option value="monthly">每月</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    `);
    
    // 绑定保存按钮事件
    $('#saveConfigBtn').on('click', function() {
        showNotification('系统配置', '系统配置已保存', 'success');
    });
}